<?php

/**
 * 包装一个类，使它可以与另一个类适配
 * Class Adapter
 */

// 狮子接口及类
interface Lion 
{
    public function roar();
}

class AfricanLion implements Lion
{
    public function roar()
    {
        echo "非洲狮";
    }
}

class AsianLion implements Lion
{
    public function roar()
    {
        echo "亚洲狮";
    }
}

// 猎人类
class Hunter
{
    public function hunt(Lion $lion)
    {
        $lion->roar();
    }
}

// 野狗类
class WildDog
{
    public function bark()
    {
        echo "野狗汪汪汪";
    }
}
// 实现了Lion接口
class WildDogAdapter implements Lion
{
    protected $dog;

    public function __construct(WildDog $dog)
    {
        $this->dog = $dog;
    }

    // 包装，使行为与狮子一致
    public function roar()
    {
        $this->dog->bark();
    }

}


// usage
$wildDog = new WildDog();
$wildDogAdapter = new WildDogAdapter($wildDog);

$hunter = new Hunter();
$hunter->hunt($wildDogAdapter);
